package com.atguigu.yygh.cmn.listen;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.mapper.DictMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @Author:hx
 * @DateTime:2022/11/4 19:11
 * @Description:
 */
public class DictListen extends AnalysisEventListener<DictEeVo> {
    private DictMapper dictMapper;

    public DictListen(DictMapper dictMapper){
        this.dictMapper = dictMapper;
    }

    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo,dict);
        Dict dict1 = dictMapper.selectById(dict.getId());
        if (dict1 == null){
            dictMapper.insert(dict);
        }else {
            dictMapper.updateById(dict);
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
